package com.jza04.flightbooking.service.impl;

import com.jza04.flightbooking.entity.Discount;
import com.jza04.flightbooking.mapper.DiscountMapper;
import com.jza04.flightbooking.service.DiscountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * 折扣服务实现类
 */
@Service
public class DiscountServiceImpl implements DiscountService {

    @Autowired
    private DiscountMapper discountMapper;
    
    @Override
    public List<Discount> findAllDiscounts() {
        return discountMapper.findAll();
    }
    
    @Override
    public Discount findDiscountById(Integer discountId) {
        return discountMapper.findById(discountId);
    }
    
    @Override
    public List<Discount> findValidDiscounts() {
        // 查询当前日期有效的折扣
        return discountMapper.findValidDiscounts(new Date());
    }
    
    @Override
    @Transactional
    public boolean addDiscount(Discount discount) {
        return discountMapper.insert(discount) > 0;
    }
    
    @Override
    @Transactional
    public boolean updateDiscount(Discount discount) {
        return discountMapper.update(discount) > 0;
    }
    
    @Override
    @Transactional
    public boolean deleteDiscount(Integer discountId) {
        return discountMapper.delete(discountId) > 0;
    }
} 